/*
 * Licensed to Jeremy Bethmont under one or more
 * contributor license agreements.  The ASF licenses this file to You
 * under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.pengyou.ooo.utils;

import java.io.File;

public class Ressources {
	private static String extensionPath = null;
	
	private static void getextensionPath() {
		if (extensionPath == null) {
			String classPath = System.getProperty("java.class.path");
			String[] tab = classPath.split(";");
			for (String s : tab) {
				int pos;
				if ((pos = s.indexOf("PengYou")) != -1 && s.indexOf(".uno.") > pos) {
					s = s.substring(0, pos + 18);
					File path = new File(s);
					extensionPath = path.getPath();
					break;
				}
			}
		}
	}
	
	public static String getImage(String name) {
		getextensionPath();
		return extensionPath + File.separator + "images" + File.separator + name;
	}
	
	public static String getFile(String name) {
		getextensionPath();
		return extensionPath + File.separator + name;
	}
}
